package operation.impl;

import book.Book;
import book.BookList;
import operation.IOperation;

import java.util.Scanner;

/**
 * 查找图书
 */
public class FindOperation implements IOperation {

    @Override
    public void work(BookList bookList) {
        System.out.println("查找图书");
        System.out.println("请输入要查找的图书：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBook(i);
            if(name.equals(book.getName())){
                System.out.println("恭喜您，找到了要查找的图书！");
                System.out.println(book);
                return;
            }
        }
        System.out.println("不好意思，没有找到您要查找的图书。");
    }
}
